﻿var MSG_TYPE_ERROR = "-1";

var MSG_TYPE_WARNING = "0";

var MSG_TYPE_INFO = "1";

var MSG_TYPE_VALIDATION = "2";

var MSG_TYPE_CONFIRM = "3"

CmnMessageCls = function () {
    this.callback = null;
}

CmnMessageCls.prototype = {
    init: function () {

        Event.observe($("cmnMessageTitle"), 'mousedown', function (event) { DragDrop.Start($("cmnMessageFrame").id, event) } .bind(this));

        Event.observe($("cmnMessageClose"), 'click', this.onClick_Close.bind(this));
        Event.observe($("cmnMessageConfirm"), 'click', this.onClick_Confirm.bind(this));
    },

    showMessage: function (msg, msgType, callback) {
        if ($("cmnMessageFrame").style.display == "none") {
            $("cmnMessageFrame").style.display = "";

            EstopLayer.show($("cmnMessageFrame"));


            ControlUtility.PopDivAlignCenter($("cmnMessageFrame"), "center");
        }

        switch (msgType) {
            case MSG_TYPE_ERROR:
                break;
            case MSG_TYPE_WARNING:
                $("cmnMessageImg").src = "../../Content/images/cmnMessage/icon_alert.gif";
                $("cmnMessageContent").style.color = "red";
                $("cmnMessageConfirm").show();
                $("cmnMessageClose").hide();
                break;
            case MSG_TYPE_INFO:
                $("cmnMessageImg").src = "../../Content/images/cmnMessage/icon_alert.gif";
                $("cmnMessageContent").style.color = "black";
                $("cmnMessageConfirm").show();
                $("cmnMessageClose").hide();
                break;
            case MSG_TYPE_VALIDATION:
                break;
            case MSG_TYPE_CONFIRM:
                $("cmnMessageConfirm").show();
                $("cmnMessageClose").show();
                break;
        }

        this.callback = callback;

        $j("#cmnMessageContent").html(msg);
    },

    showProcessing: function () {
        $("cmnMessageImg").src = "../../Content/images/cmnMessage/65.gif";
        $("cmnMessageConfirm").hide();
        $("cmnMessageClose").hide();

        if ($("cmnMessageFrame").style.display == "none") {
            $("cmnMessageFrame").style.display = "";

            EstopLayer.show($("cmnMessageFrame"));

            ControlUtility.PopDivAlignCenter($("cmnMessageFrame"), "center");
        }
        $("cmnMessageContent").style.color = "blue";
        $j("#cmnMessageContent").html("加载中...");
    },

    onClick_Close: function () {
        this.hide();
    },

    onClick_Confirm: function () {
        this.hide();

        if (typeof this.callback == "function") {
            this.callback();

            this.callback = null;
        }
    },

    hide: function () {
        EstopLayer.hide($("cmnMessageFrame"));

        $("cmnMessageFrame").style.display = 'none';
    }
}

CmnMessage = new CmnMessageCls();